# -*- coding:utf-8 -*-

from fastapi import Depends
from sqlalchemy.orm import Session

from app.models.data.user import TbUser
from app.models.request.user import User
from app.repository.core import BaseRepository

from core.database import get_db

class UserRepository(BaseRepository):
    def __init__(self, db: Session=Depends(get_db)):
        self.db = db
        self.table = TbUser
        self.model = User 
        
    async def get_user_by_username(self, username: str):
        """
            SELECT * FROM users WHERE username = $1 AND del_flag = 0
        """
        return self.db.query(TbUser).filter(TbUser.account==username, TbUser.del_flag==0).one_or_none()

    async def get_user_by_email(self, email: str):
        """
            SELECT * FROM users WHERE email = $1 AND del_flag = 0
        """
        return self.db.query(TbUser).filter(TbUser.email==email, TbUser.del_flag==0).one_or_none()

    async def get_user_by_mobile(self, mobile: str):
        """
            SELECT * FROM users WHERE mobile = $1 AND del_flag = 0
        """
        return self.db.query(TbUser).filter(TbUser.mobile==mobile, TbUser.del_flag==0).one_or_none()

